<!--
 * @Author: huo-l huo-l@neusoft.com
 * @Date: 2022-06-17 09:54:35
 * @LastEditors: your name
 * @LastEditTime: 2022-07-14 10:58:13
 * @FilePath: /gua-dev-starter/src/modules/[...all].vue
 * @Discription:
-->
<route>
{
    name: 'notFound',
    meta: {
        title: "找不到页面",
        hidden: true
    }
}
</route>
<template>
  <div class="notfound">
    <svg-icon name="404" class="icon" />
    <div class="content">
      <h1>404</h1>
      <div class="desc">抱歉，你访问的页面不存在</div>
      <el-button type="primary" @click="goBack">{{ data.countdown }} 秒后，返回首页</el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { onBeforeRouteLeave, useRouter } from 'vue-router'
const router = useRouter()

const data = ref({
  inter: null,
  countdown: 5,
})

onBeforeRouteLeave(() => {
  clearInterval(data.value.inter)
})

onMounted(() => {
  data.value.inter = setInterval(() => {
    data.value.countdown--
    if (data.value.countdown == 0) {
      clearInterval(data.value.inter)
      goBack()
    }
  }, 1000)
})

function goBack() {
  router.push('/')
}
</script>
<style lang="scss" scoped>
// 定位居中，默认水平居中，可选择垂直居中，或者水平垂直都居中
@mixin position-center($type: x) {
  position: absolute;
  @if ($type == x) {
    left: 40%;
    transform: translateX(-50%);
  }
  @if ($type == y) {
    top: 40%;
    transform: translateY(-50%);
  }
  @if ($type == xy) {
    left: 40%;
    top: 40%;
    transform: translateX(-50%) translateY(-50%);
  }
}
.notfound {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 700px;
  @include position-center(xy);
  .icon {
    width: 400px;
    height: 400px;
  }
  .content {
    h1 {
      margin: 0;
      font-size: 72px;
      color: #303133;
    }
    .desc {
      margin: 20px 0 30px;
      font-size: 20px;
      color: #606266;
    }
  }
}
</style>
